﻿//-----------------------------------------------------------------------
// <copyright file="Parameters.cs" company="Craig Longford">
//     Copyright (c) Craig Longford. All rights reserved.
//     Email: deltawolf7@gmail.com
//     WWW: http://www.deltasblog.co.uk
// </copyright>
//-----------------------------------------------------------------------

namespace Delta.Data.DataExpress
{
    using System.Collections.Generic;
    using System.Data;

    /// <summary>
    /// Parameters collection
    /// </summary>
    public class Parameters : List<Parameter>
    {
        #region Constructors
        /// <summary>
        /// Initializes a new instance of the Parameters class.
        /// </summary>
        public Parameters()
        {
        }

        /// <summary>
        /// Initializes a new instance of the Parameters class.
        /// </summary>
        /// <param name="parameters">Parameters array</param>
        public Parameters(Parameter[] parameters)
        {
            foreach (Parameter parameter in parameters)
            {
                this.Add(parameter);
            }
        }
        #endregion

        #region Get Parameters
        /// <summary>
        /// Get parameters for use within command.
        /// </summary>
        /// <param name="command">Reference to command</param>
        internal void GetParameters(ref IDbCommand command)
        {
            foreach (Parameter parameter in this)
            {
                IDbDataParameter param = command.CreateParameter();
                param.Value = parameter.Value;
                param.ParameterName = parameter.Name;
                command.Parameters.Add(param);
            }
        }
        #endregion
    }
}
